<template>
    <el-table
            :data="tableData"
            style="width: 90%;margin: auto"
            max-height="500">
        <el-table-column
                fixed
                prop="CouName"
                label="CouName"
                width="200">
        </el-table-column>
        <el-table-column
                prop="Kind"
                label="Kind"
                width="120">
        </el-table-column>
        <el-table-column
                prop="Teacher"
                label="Teacher"
                width="120">
        </el-table-column>
        <el-table-column
                prop="SchoolTime"
                label="SchoolTime"
                width="120">
        </el-table-column>
        <el-table-column
                prop="ChooseNum"
                label="ChooseNum"
                width="120">
        </el-table-column>
        <el-table-column
                prop="LimitNum"
                label="LimitNum"
                width="120">
        </el-table-column>
        <el-table-column
                prop="WillNum"
                label="WillNum"
                width="120">
        </el-table-column>
        <el-table-column
                fixed="right"
                label="操作"
                width="120">
            <template v-slot="scope">
                <el-button
                        @click="deleteRow(scope.row.CouNo)"
                        type="text"
                        size="small">
                    移除
                </el-button>
            </template>
        </el-table-column>
    </el-table>
</template>

<script>
   import qs from "qs";

   const axios = require('axios');
    export default {
        methods: {
            deleteRow(CouNo) {
                let postData = qs.stringify({ CouNo:CouNo,StuNo:'00000001'});
                axios.post("http://localhost/delstucou.php",postData)
                    .then((res) => {
                        console.log(res.data)
                        if(res.data.respon==true){
                            this.$message({
                                message: '删除成功',
                                center: true,
                                type: 'success'
                            });
                            sessionStorage.setItem('row',res.data.row);
                            this.$router.go(0);
                        }else {
                            this.$message({
                                message: '删除失败',
                                center: true,
                                type: 'error'
                            });
                        }
                    }).catch((err) => {
                    console.log(err)
                    alert(err);
                })

            }
        },

        data() {
            return {
                tableData: []
            }
        },created() {
            axios.get("http://localhost/stucourse.php?stuno=00000001")
                .then((res) => {
                    this.tableData=res.data.data
                    sessionStorage.setItem('row',res.data.row);
                    console.log(res.data.data);
                })
                .catch((err) => {
                    console.log(err)
                    alert(err);
                })
        }
    }
</script>